//
//  SearchSaleView.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/11.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "SearchSaleView.h"
#import "GYMineLikeProductCell.h"
#import "Head.h"
#import "GYSearchViewModel.h"
@interface SearchSaleView ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)GYSearchViewModel * shopInfoModel;
@end
@implementation SearchSaleView
-(GYSearchViewModel *)shopInfoModel
{
    if (!_shopInfoModel) {
        _shopInfoModel=[[GYSearchViewModel alloc] init];
    }
    return _shopInfoModel;
}
-(GCBaseTableView *)myTable
{
    if (!_myTable) {
        _myTable=[[GCBaseTableView alloc]initWithFrame:self.bounds style:UITableViewStyleGrouped];
        _myTable.delegate=self;
        _myTable.dataSource=self;
        _myTable.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
        _myTable.backgroundColor=[UIColor whiteColor];
        [_myTable setSeparatorColor: Main_Color_BG];
    }
    return _myTable;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.myTable];
    }
    return self;
}

#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.shopInfoModel.saleArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellID = @"CellID";
    GYMineLikeProductCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[GYMineLikeProductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    @WeakSelf
    [cell.deleteBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
        [selfp tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
    }];
    GYMineLikeProductInfoModel *model = self.shopInfoModel.saleArr[indexPath.row];
    cell.model = model;
    [cell.deleteBtn setHidden:YES];
    
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = WFCGFloatY(104);
    return height;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return .0001f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return .0001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GYMineLikeProductInfoModel *model = self.shopInfoModel.saleArr[indexPath.row];
    _callBack(model.id);
}
-(void)refresh:(GYSearchViewModel *)model
{
    _shopInfoModel=model;
    [_myTable reloadData];
}

@end
